package cn.chen.miaosha.dao;

import cn.chen.miaosha.domain.MiaoshaOrder;
import cn.chen.miaosha.domain.OrderInfo;
import org.apache.ibatis.annotations.*;

@Mapper
public interface OrderDao {

    @Select("select * from miaosha_order where user_id=#{userId} and goods_id=#{goodsId}")
    MiaoshaOrder getMiaoshaOrderByUserIdGoodsId(@Param("userId") Long userId,@Param("goodsId") Long goodsId);

    @Insert("insert into order_info(user_id, goods_id, goods_name, goods_price ,order_channel," +
            " status, create_date)values(#{userId},#{goodsId},#{goodsName},#{goodsPrice}, " +
            "#{orderChannel},#{status},#{createDate})")
    @SelectKey(keyColumn = "id", keyProperty = "id", resultType = long.class, before = false,
    statement = "select last_insert_id()")
    long insert(OrderInfo orderInfo);

    @Insert({"insert into miaosha_order(user_id, order_id, goods_id)Values(#{userId},#{orderId},#{goodsId})"})
    int insertMiaoshaOrder(MiaoshaOrder miaoshaOrder);

    @Select("select * from order_info where id=#{orderId}")
    OrderInfo getOrderById(@Param("orderId") Long orderId);
}
